const TIM = require('../../TUIKit/lib/tim-wx-sdk')
import { genTestUserSig }  from '../../TUIKit/debug/GenerateTestUserSig'
import TIMUploadPlugin from '../../TUIKit/lib/tim-upload-plugin'
Page({
data: {
    config: {
        userID: '', //User ID
        SDKAPPID: 0, // Your SDKAppID
        SECRETKEY: '', // Your secretKey
        EXPIRETIME: 0

    }
},
 onLoad(e) {
   console.log(e)
   let _this = this

      _this.setData({
        config:{
          userID:e.IMuser,
          SDKAPPID: 1400759366, // Your SDKAppID
        SECRETKEY: '0ea1bb9566022c89351ae2d2484007a0502e1c728cd6373c0aa4c31cf2101381', // Your secretKey
        EXPIRETIME: 604800
        }
      })
    const userSig = genTestUserSig(this.data.config).userSig 
    wx.$TUIKit = TIM.create({
        SDKAppID: this.data.config.SDKAPPID
    })
    wx.$chat_SDKAppID = this.data.config.SDKAPPID;
    wx.$chat_userID = this.data.config.userID;
    wx.$chat_userSig = userSig;
    wx.$TUIKitTIM = TIM;
    wx.$TUIKit.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin });            
    wx.$TUIKit.login({
        userID: this.data.config.userID,
        userSig
    });
    wx.setStorage({
        key: 'currentUserID',
        data: [],
    });
    wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady,this);
 
},
onUnload() {
    wx.$TUIKit.off(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady,this);
},
onSDKReady() {
    const TUIKit = this.selectComponent('#TUIKit');
    TUIKit.init();
}
});